from ast import parse
from aiogram import F, Router, types, html
from aiogram.enums import ParseMode
from aiogram.filters import CommandStart, Command
from aiogram.utils import markdown
from aiogram.types import ReplyKeyboardRemove

from keyboards.common_keyboards import share_phone_kb
from utils.api_requests import get_ads_list_request


router = Router(name=__name__)


@router.message(CommandStart())
async def command_start_handler(message: types.Message):
    user_name = message.from_user.first_name if message.from_user else "Уважаемый/ая"
    await message.answer(
        text=(
            f"Здравствуйте, {html.bold(user_name)}!\n"
            f"Для  привязки чата к сканеру Авито {html.bold("нажмите кнопку")}"
            ),
        parse_mode=ParseMode.HTML,
        reply_markup=share_phone_kb(),
    )


@router.message(Command("list", prefix="!/"))
async def command_list_handler(message: types.Message):
    response = await get_ads_list_request(chat_id=message.chat.id)

    for string in response:
        await message.answer(text=string, parse_mode=ParseMode.HTML)
